package com.ll.menu.user.welcome;

import android.os.Bundle;
import android.text.Html;
import android.view.View;
import android.widget.TextView;

import com.droid.library.app.App;
import com.droid.library.app.mvp.BaseMVPActivity;
import com.droid.library.app.mvp.IUI;
import com.ll.menu.user.R;
import com.ll.menu.user.dialog.ManagerDialog;
import com.ll.menu.user.menu.MenuActivity;

import butterknife.InjectView;
import butterknife.OnClick;

/**
 * 欢迎页面
 *
 * @author wangheng
 */
public class WelcomeActivity extends BaseMVPActivity<WelcomePresenter> implements IWelcomeUI {

    @InjectView(R.id.tvWelcomeEditText)
    TextView mTextView;

    @InjectView(R.id.tvWelcomeCurrent)
    TextView mCurrentTextView;

    @InjectView(R.id.tvWelcomeSwitch)
    TextView mSwitchTextView;

    private String mCurrentTabFormat = "";
    private String mCurrentRoomFormat = "";
    private String mCountFormat = "";

    @Override
    protected int getLayoutId() {
        return R.layout.activity_welcome;
    }

    @Override
    protected void onCreateExecute(Bundle savedInstanceState) {

        mCurrentTabFormat = App.getInstance().getString(R.string.current_table);
        mCurrentRoomFormat = App.getInstance().getString(R.string.current_room);

        mCountFormat = App.getInstance().getString(R.string.people_count_mode);

        mCurrentTextView.setText(String.format(mCurrentTabFormat,20));

        mSwitchTextView.setText(Html.fromHtml("<u>"
                + App.getInstance().getString(R.string.table_switch) + "</u>"));
    }

    @Override
    protected WelcomePresenter createPresenter() {
        return new WelcomePresenter();
    }

    @Override
    protected IUI getUI() {
        return WelcomeActivity.this;
    }

    @OnClick({R.id.tvWelcomeButton,R.id.tvWelcomeSwitch,R.id.tvWelcomeEditText})
    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.tvWelcomeButton:
                MenuActivity.launch(WelcomeActivity.this);
                break;
            case R.id.tvWelcomeSwitch:
                new ManagerDialog(this).show();
                break;
            case R.id.tvWelcomeEditText:
                CountPopupWindow popup = new CountPopupWindow(this,mTextView.getWidth());
                popup.setOnItemSelectListener(new CountPopupWindow.OnItemSelectListener() {
                    @Override
                    public void onItemSelect(int count) {
                        mTextView.setText(String.format(mCountFormat,count));
                    }
                });
                popup.showAsDropDown(mTextView);
                break;
            default:

                break;
        }
    }
}
